//
//  TouchsDelayRecognizer.m
//  TouchMeBaby
//
//  Created by 丁诚昊(831) on 15-6-10.
//  Copyright (c) 2015年 丁诚昊(831). All rights reserved.
//

#import "TouchsDelayRecognizer.h"
#import <UIKit/UIGestureRecognizerSubclass.h>

@implementation TouchsDelayRecognizer{
    NSTimer* _timer;
}

- (instancetype) initWithTarget:(id)target action:(SEL)action{
    if (self = [super initWithTarget:target action:action]) {
        self.delaysTouchesBegan = YES;
    }
    return self;
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    _timer = [NSTimer scheduledTimerWithTimeInterval:.12f target:self selector:@selector(fail) userInfo:nil repeats:NO];
}

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
    [self fail];
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self touchesCancelled:touches withEvent:event];
}

- (void)fail{
    self.state = UIGestureRecognizerStateFailed;
}

- (void)reset{
    [_timer invalidate];
    _timer = nil;
}
@end
